package main

import (
	"fmt"

	_ "github.com/go-sql-driver/mysql"
	"github.com/jmoiron/sqlx"
)

func initmysql() {
	dsn := "ll:ll123@tcp(124.221.160.244:90)/test"
	db2, err := sqlx.Open("mysql", dsn)
	if err != nil {
		panic(err)
	}
	defer db2.Close() // 注意这行代码要写在上面err判断的下面
	queryMultiRowDemo(db2)
}
func queryMultiRowDemo(db *sqlx.DB) {
	rows, err := db.Query("SELECT * FROM code")
	if err != nil {
		fmt.Println("select db failed,err:", err)
		return
	}
	for rows.Next() {
		ls, err := rows.Columns()
		if err != nil {
			fmt.Println(ls[0])
			return
		}
		fmt.Println(ls)
	}
	rows.Close()
}
